const Mock = require('mockjs');
const Random = Mock.Random;
const produceNewsData = function(len) {
    var len = len || 10;
    let data = [];
    for (let i = 0; i < len; i++) {
        let newArticleObject = Mock.mock({
            "sex|1":[
                '男','女'
            ],"name":'@cname'
        })
        data.push(newArticleObject)
    }
 
    return {
        data: data,
        total: Random.integer(0,10000)
    }
}

Mock.setup({
    timeout: '1000-2000' // 表示响应时间介于 200 和 600 毫秒之间，默认值是'10-100'。
})
// Mock.mock( url, post/get , 返回的数据)；
    Mock.mock(/\/news\/index/, 'get', function(option){
        var paramsStr = option.url.split('?')[1].split('&');
        var params = {}
            paramsStr.forEach((param)=>{
                var keyValue = param.split('='),
                key = keyValue[0],
                value = keyValue[1];
                params[key] = value;
        })
        console.log(params)
        var pageSize = params['pageSize'] || 10;
        return produceNewsData(pageSize);
    });